if(!window.mc){
	window.mc = function(){};
}
mc.init = function(url,chanel){
	mc.url = url;
	mc.rid = 1000;
	mc.sid = "";
	mc.def_chanel = chanel;
	mc.cbs = {};
	mc.last_check = false;
}
mc.start = function(login,pass){
	mc.login = login;
	mc.SendMessage("login",{pass:pass},mc.login_handler);
}
mc.SendMessage = function(cmd,msg,callback){
	if(!msg.rid){
		msg.rid = mc.rid++;
	}
	msg.sid = mc.sid;
	if(!msg.chanel){
		msg.chanel = mc.def_chanel;
	}
	if(callback){
		mc.cbs[msg.rid] = callback;
	}
	$.ajax({
		url: mc.url+"/"+cmd,
		type: "POST",
		dataType: "json",
		success: mc.read_handler,
		error: mc.error_handler,
		timeout: 60*1000,
		data: msg
	});
}
mc.read_handler = function(data, textStatus, jqXHR){
	if(data.rid && mc.cbs[rid]){
		mc.cbs[rid].call(data);
	}
	switch(data.type){
		case "response":
			break;
		case "list":
			break;
		case "message":
			break;
		default:
	}
}
mc.error_handler = function(jqXHR, textStatus, errorThrown){
}
